package com.spt.springbootzhsx.controller;

import com.spt.springbootzhsx.entity.Comment;
import com.spt.springbootzhsx.entity.back.CommentBack;
import com.spt.springbootzhsx.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping(value="/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @PostMapping(value="/addComment")
    public String addComment(@RequestBody Comment comment){
        return commentService.addComment(comment);
    }

    @GetMapping(value = "/getAllComment")
    public ArrayList<CommentBack> getAllComment(){
        return commentService.getAllComment();
    }

    @GetMapping("/getAllCommentByMid/{mid}")
    public ArrayList<CommentBack> getAllCommentByMid(@PathVariable("mid") Integer mid){
        return commentService.getAllCommentByMid(mid);
    }

    @GetMapping("/deleteComment/{coid}")
    public String deleteComment(@PathVariable("coid") Integer coid){
        return commentService.deleteComment(coid);
    }

    @GetMapping("/getCommentByUnameOrMname/{key}")
    public ArrayList<CommentBack> getCommentByUnameOrMname(@PathVariable("key") String key){
        return commentService.getCommnetByUnameOrMname(key);
    }
}
